﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Text;
using Aandelendelen.String;

namespace Aandelendelen.Mail
{
	internal class AdminMail : EMail
	{
		internal AdminMail(string name)
			: base (name)
		{
		}

		internal AdminMail(string name, string body)
			: base (name, body)
		{
		}

		protected override void ReadMail(string name, string body)
		{
			string path = HttpContext.Current.Server.MapPath("/App_Data/AdminMail.xml");

			this.Load(path);

			XmlNode node = this.SelectSingleNode("/aandelendelen/mail[@name='" + name + "']");

			StringBuilder str = new StringBuilder(body == null ? (node == null ? null : node.InnerXml.Clean()) : body);
			this.subject = (node == null ? name : node.Attributes["subject"].Value);

			this.sendBody = str.ToString();

			if (node != null)
				this.ReadPSAllowed(node);

			this.RemoveAll();
		}

		protected override void ReadMail(string name)
		{
			this.ReadMail(name, null);
		}

		//internal void Queue(StringCollection recipients)
		//{
		//    this.Recipients = recipients[0];

		//    BulkEMail emails = new BulkEMail();
		//    emails.Add(this);

		//    //int textId = this.QueueSingle(false);

		//    for (int i = 1; i < recipients.Count; i++)
		//    {
		//        EMail newMail = new EMail(this);

		//        newMail.Recipients = recipients[i];

		//        emails.Add(newMail);
		//    }

		//    emails.Send();
		//}
	}
}